project(LilyDict)
cmake_minimum_required(VERSION 3.3)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5Widgets)
find_package(Qt5Qml)
if(UNIX)
    SET(CMAKE_FIND_LIBRARY_SUFFIXES .a .so)
else()
    SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll)
endif()
#SET( CMAKE_VERBOSE_MAKEFILE on )
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)

if(COMPILER_SUPPORTS_CXX11)
    set(STD_CXX -std=c++11)
endif()
if(COMPILER_SUPPORTS_CXX14)
    set(STD_CXX -std=c++14)
endif()
if(NOT STD_CXX)
    message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 C++14 support. Please use a different C++ compiler.")
endif()

set(CMAKE_BUILD_TYPE "Release")
if(CMAKE_BUILD_TYPE STREQUAL "Debug" )
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STD_CXX} -g -Wall -Wno-unused-variable -pthread")
else()
    set(CMAKE_BUILD_TYPE "Release")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STD_CXX} -fno-strict-aliasing -Wno-unused-but-set-variable -Wno-deprecated")
endif(CMAKE_BUILD_TYPE STREQUAL "Debug" )
message("Build Type:" ${CMAKE_BUILD_TYPE} ${CMAKE_CXX_FLAGS})

INCLUDE_DIRECTORIES(./src)
aux_source_directory(./src SRC_LIST)
aux_source_directory(./src/app SRC_LIST)
aux_source_directory(./src/gui SRC_LIST)
aux_source_directory(./src/net SRC_LIST)
# Set some Win32 Specific Settings
IF(WIN32)
SET(GUI_TYPE WIN32)
ENDIF(WIN32)
# Set some Apple MacOS Specific settings
IF (APPLE)
SET(GUI_TYPE MACOSX_BUNDLE)
ENDIF (APPLE)
add_executable(${PROJECT_NAME} ${GUI_TYPE} ${SRC_LIST} qml.qrc icons.qrc app.rc)

if(UNIX)
    set(LINK_FLAGS "-lpthread -ldl -lgmp")
endif()
target_link_libraries(${PROJECT_NAME}  ${LINK_FLAGS} Qt5::Widgets Qt5::Qml)
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION dict)

INCLUDE(InstallRequiredSystemLibraries)

SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LilyDict 1.0.0")
SET(CPACK_PACKAGE_VENDOR "Lieefu Way")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
SET(CPACK_PACKAGE_VERSION_MAJOR "2")
SET(CPACK_PACKAGE_VERSION_MINOR "0")
SET(CPACK_PACKAGE_VERSION_PATCH "0")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "lilydict")
IF(WIN32 AND NOT UNIX)
    # There is a bug in NSI that does not handle full unix paths properly. Make
    # sure there is at least one set of four (4) backlasshes.
    SET(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/img\\\\logo.bmp")
    SET(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}\\\\app.ico")
    SET(CPACK_NSIS_INSTALLED_ICON_NAME "LilyDict.exe")
    SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} My Famous Project")
    SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\www.lieefu.com")
    SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.lieefu.com")
    SET(CPACK_NSIS_CONTACT "lieefu@gmail.com")
    SET(CPACK_NSIS_MODIFY_PATH ON)
ELSE(WIN32 AND NOT UNIX)
    SET(CPACK_GENERATOR "DEB")
    SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Lieefu Way") #required
    SET(CPACK_STRIP_FILES "LilyDict")
    SET(CPACK_SOURCE_STRIP_FILES "")
ENDIF(WIN32 AND NOT UNIX)
SET(CPACK_PACKAGE_EXECUTABLES "LilyDict" "My LilyDict")
INCLUDE(CPack)

